package demo.c1;

/**
 * Template desgin pattern
 *
 * @author chisheng
 */
public class TemplateMethod {

    /* public class Thread implements Runnable {
     *     // Logical implementation method
     *     @Override
     *     public void run() { ... }
     *     // Logic control method
     *     public synchronized void start() { ... }
     *  } */

    /**
     * Logic control method
     *
     * @param message message
     */
    public final void print(String message) {
        System.out.println("**************************************");
        wrapPrint(message);
        System.out.println("**************************************");
    }

    /**
     * Logical implementation method
     *
     * @param message message
     */
    public void wrapPrint(String message) {
    }

    /**
     * Test
     */
    public static void main(String[] args) {
        final TemplateMethod template0 = new TemplateMethod() {
            @Override
            public void wrapPrint(String message) {
                System.out.println("> " + message);
            }
        };

        final TemplateMethod template1 = new TemplateMethod() {
            @Override
            public void wrapPrint(String message) {
                System.out.println("$ " + message);
            }
        };

        template0.wrapPrint("template0");
        template1.wrapPrint("template1");
    }

}
